<?php

class AdvertisementsPublicController extends Controller {

	public $uses = array("Advertisement");
	public $components = array('Paginator');
	public $helpers = array('Paginator');
	
	public function index() {
		$paginate = array();
		$paginate['conditions'] = array('status_id' => 2);
		$paginate['limit'] = 4;
		$paginate['order'] = array(
				'Advertisement.title' => 'asc'
		);
		$this->Paginator->settings = $paginate;
		$adverts = $this->Paginator->paginate('Advertisement');
		$this->set('advertisements', $adverts);
		$this->set('isLoggedUserAdmin', 0);
		$this->layout = "public";
	}
	
	public function detail($id) {
		$this->Advertisement->id = $id;
		
		if ($this->request->is('get')) {
			if (!$this->Advertisement->exists()) {
				throw new NotFoundException(__('Brak takiego ogłoszenia'), 'msg');
			}
			$item = $this->Advertisement->findById($id);
			$item['Advertisement']['content'] = str_replace("\\n", "<br/>", $item['Advertisement']['content']);
			$this->set('advertisement', $item);
		}
		$this->layout = "public";
	}
}